<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="X-admin/js/jquery.js"></script>
</head>
<body>
　
<div id="timer">
    支付倒计时：<span></span>分<span></span>秒
</div>
</div>
</body>
<script>
    //获取到期时间的毫秒数
    let date = new Date("2021-07-08 18:24:33")
    console.log(date)
    let time = date.getTime() + 1800 * 1000;

    //获取到当前时间的毫秒数
    let date1 = new Date();
    let times1 = date1.getTime();

    //获取两者的差值
    let times = time - times1;

    //将差值放入到倒计时方法中
    resetTime(times / 1000);

    //倒计数方法
    function resetTime(time) {
        var timer = null;
        var t = time;
        var m = 0;
        var s = 0;
        var $span = $('#timer span');
        m = Math.floor(t / 60 % 60);
        m < 10 && (m = '0' + m);
        s = Math.floor(t % 60);

        function countDown() {
            s--;
            s < 10 && (s = '0' + s);
            if (s.length >= 3) {
                s = 59;
                m = "" + (Number(m) - 1);
            }
            if (m.length >= 45) {
                m = '00';
                s = '00';
                clearInterval(timer);
            }
            $span.eq(0).html(m);
            $span.eq(1).html(s);
            // console.log(m+"分钟"+s+"秒");
        }

        timer = setInterval(countDown, 1000);
    }


</script>
</html>